# -*- coding: utf-8 -*-
'''
Created on Sep 1, 2019

@author: yl
'''
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from Frames_set_Compare import Frame_set, frame_total, fs_cam

print(len(Frame_set))
print(len(Frame_set[0]))
print(len(Frame_set[0][0]))

def frame(num):
    return Frame_set[num]

num = 0

fig = plt.figure(1)
im = plt.imshow(frame(num),cmap='gray', animated=True)
plt.colorbar(im, fraction=0.046, pad=0.04)
line, = plt.plot((-frame(num)[512]/2+1000), color='white')
line_ver, = plt.plot(frame(num)[:,512]/2+50, np.arange(1024), color='white')

def updatefig(*args):
    global num
    im.set_array(frame(num))
    line.set_ydata(-frame(num)[512]/2+1000)
    line_ver.set_xdata(frame(num)[:,512]/2+50)
    num = num+1
    if num == frame_total:
        num = 0
#         quit()
    return im, line, line_ver
ani = animation.FuncAnimation(fig, updatefig, interval=200, blit=True)
plt.show()
# ani.save('test.gif', writer=animation.PillowWriter(fps=50))
# ani.save('test.gif')
# print('finish')